package com.huluobo.a2204kotlinjetpackdemo.news

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.google.gson.Gson
import com.huluobo.a2204kotlinjetpackdemo.R
import com.huluobo.a2204kotlinjetpackdemo.databinding.ActivityNewsBinding
import com.huluobo.base.bean.NewsBean
import com.huluobo.base.mvvm.BaseActivity
import com.huluobo.base.net.Const
import dagger.hilt.android.AndroidEntryPoint
import okhttp3.MediaType
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody

@AndroidEntryPoint
class NewsActivity : BaseActivity<ActivityNewsBinding, NewsViewModel>() {
    override fun initData() {
        val map = mutableMapOf<String, Int>()
        map[Const.PARAM_PAGE] = 0

        val json = Gson().toJson(map)
        val body = RequestBody.create("application/json;charset=utf-8".toMediaTypeOrNull(), json)
        viewModel.getNews(body)

        viewModel.getNewsSuccess.observe(this) {
            val list = Gson().fromJson(it, NewsBean::class.java)
            Log.i("TagA", "item:${list[0]}")
        }
    }

    override fun initView() {

    }
}